package com.legal.app.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.legal.app.domain.vo.LawyerHomeVO;
import com.legal.app.domain.vo.LawyerVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.legal.common.annotation.Log;
import com.legal.common.core.controller.BaseController;
import com.legal.common.core.domain.AjaxResult;
import com.legal.common.enums.BusinessType;
import com.legal.app.domain.Lawyer;
import com.legal.app.service.ILawyerService;
import com.legal.common.utils.poi.ExcelUtil;
import com.legal.common.core.page.TableDataInfo;

/**
 * 律师Controller
 * 
 * @author ALe
 * @date 2025-05-30
 */
@Api(tags = "律师模块")
@RestController
@RequestMapping("/app/lawyer")
public class LawyerController extends BaseController
{
    @Autowired
    private ILawyerService lawyerService;

    /**
     * 查询律师列表
     */
    @PreAuthorize("@ss.hasPermi('app:lawyer:list')")
    @GetMapping("/list")
    @ApiOperation("律师列表查询")
    public TableDataInfo list(Lawyer lawyer)
    {
        startPage();
        List<Lawyer> list = lawyerService.selectLawyerList(lawyer);
        return getDataTable(list);
    }

    /**
     * 导出律师列表
     */
    @PreAuthorize("@ss.hasPermi('app:lawyer:export')")
    @Log(title = "律师", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出律师列表")
    public void export(HttpServletResponse response, Lawyer lawyer)
    {
        List<Lawyer> list = lawyerService.selectLawyerList(lawyer);
        ExcelUtil<Lawyer> util = new ExcelUtil<Lawyer>(Lawyer.class);
        util.exportExcel(response, list, "律师数据");
    }

    /**
     * 获取律师详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:lawyer:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("律师详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(lawyerService.selectLawyerById(id));
    }

    /**
     * 新增律师
     */
    @PreAuthorize("@ss.hasPermi('app:lawyer:add')")
    @Log(title = "律师", businessType = BusinessType.INSERT)
    @ApiOperation("新增律师")
    @PostMapping
    public AjaxResult add(@RequestBody Lawyer lawyer)
    {
        return toAjax(lawyerService.insertLawyer(lawyer));
    }

    /**
     * 修改律师
     */
    @PreAuthorize("@ss.hasPermi('app:lawyer:edit')")
    @Log(title = "律师", businessType = BusinessType.UPDATE)
    @ApiOperation("修改律师")
    @PutMapping
    public AjaxResult edit(@RequestBody Lawyer lawyer)
    {
        return toAjax(lawyerService.updateLawyer(lawyer));
    }

    /**
     * 删除律师
     */
    @ApiOperation("律师列表查询")
    @PreAuthorize("@ss.hasPermi('app:lawyer:remove')")
    @Log(title = "律师", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lawyerService.deleteLawyerByIds(ids));
    }


    /**
     * 获取首页在线律师列表（VO版本）
     * @param pageSize 每页数量（默认10条）
     * @param pageNum 页码（默认第1页）
     * @return 包含律师关键信息的VO列表
     */
    @PreAuthorize("@ss.hasPermi('app:lawyer:home')")
    @GetMapping("/home")
    @Log(title = "首页律师列表", businessType = BusinessType.OTHER)
    @ApiOperation("首页律师列表查询")
    public AjaxResult getHomeLawyers(
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "1") Integer pageNum) {
        return lawyerService.getHomeLawyers(pageSize, pageNum);
    }

    /**
     * 获取首页律师列表（VO版本）
     * @param vo 查询条件
     * @return 符合查询条件的律师列表
     */
    @PostMapping("/query")
    @ApiOperation("首页律师条件查询")
    @PreAuthorize("@ss.hasPermi('app:lawyer:query')")
    @Log(title = "律师", businessType = BusinessType.OTHER)
    public AjaxResult queryLawyers(@RequestBody LawyerHomeVO vo) {
        return lawyerService.queryLawyersByCondition(vo);
    }

    /**
     * 获取律师详情
     */
    @PreAuthorize("@ss.hasPermi('app:lawyer:detail')")
    @GetMapping("/detail/{lawyerId}")
    @ApiOperation("律师详情查询")
    public AjaxResult getLawyerDetail(@PathVariable("lawyerId") Long lawyerId) {
        LawyerVO lawyerVO = lawyerService.getLawyerDetail(lawyerId);
        return AjaxResult.success(lawyerVO);
    }

}
